<template>
  <uploader :options="options"
            :file-status-text="statusText"
            class="uploader-example"
            ref="uploader"
            @file-added="fileAdded">
    <uploader-unsupport></uploader-unsupport>
    <uploader-drop>
      <uploader-btn>选择文件</uploader-btn>
      <span>文件限制最大
        <span style="color:red">100M</span>
        且名称不能超过
        <span style="color:red">50个</span>
        字符!
      </span>
    </uploader-drop>
    <uploader-list></uploader-list>
  </uploader>
</template>

<script>
  import {getPath} from "../../assets/commonjs/env";

  export default {
    name:'fileuploader',
    props:['fileInfo'],
    data () {
      return {
        options: {
          target: getPath('api_path')+'fileserver/upload',
          testChunks: true,
          query:{
            fileParam:JSON.stringify(this.fileInfo),
          },
        },
        statusText: {
          success: '成功了',
          error: '出错了',
          uploading: '上传中',
          paused: '暂停中',
          waiting: '等待中'
        }
      }
    },
    methods: {
      fileAdded (file) {
        if (file.size > 100 * 1024 * 1024) {
          console.log(file.name+"文件过大！");
          file.ignored = true;
        }
        if(file.name.length>50){
          console.log(file.name+"文件名过长！");
          file.ignored = true;
        }
      }
    },
    mounted () {
      this.$nextTick(() => {
        window.uploader = this.$refs.uploader.uploader
      })
    }
  }
</script>

<style>
  .uploader-example {
    width: 100%;
    box-sizing: border-box;
    padding: 15px;
    margin: 40px auto 0;
    font-size: 12px;
    box-shadow: 0 0 10px rgba(0, 0, 0, .4);
  }
  .uploader-example .uploader-btn {
    margin-right: 4px;
  }
  .uploader-example .uploader-list {
    max-height: 440px;
    overflow: auto;
    overflow-x: hidden;
    overflow-y: auto;
  }
</style>
